const express = require("express");
const { singers } = require("./singers.json");

const app = express();
const port = 3000;

app.get("/singer/:id.html", (req, res) => {
  const { id } = req.params;
  const singer = singers.find((o) => o.id === Number(id));

  if (singer) {
    res.end(`
      <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="UTF-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Document</title>
        </head>
        <body>
          <h2>${singer.singer_name}</h2>
          <img src="${singer.singer_pic}" alt="">
        </body>
      </html>
    `);
  } else {
    res.statusCode = 404;
    res.end("404 Not Found");
  }
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
